var ActorWalk = cc.Sprite.extend({
    appearPosition:cc.p(MW.ACTOR.X, MW.ACTOR.Y),
    fightPosition:cc.p(MW.ACTOR.X-200, MW.ACTOR.Y-200),
    zOrder:3000,
    fightFrames:[],
    fightAnimate:null,
    fightAnimation:null,
    walkFrames:[],
    walkAnimate:null,
    walkAnimation:null,
    deadFrames:[],
    deadAnimate:null,
    deadAnimation:null,
    initW:0,
    initH:0,
    ctor:function () {
        this._super('#wx_standby_01.png');
        this.attr({
            anchorX: 0.5,
            anchorY: 0.5
        });
        this.tag = this.zOrder;

        this.backposition(this);
        this.initW = this.width;
        this.initH = this.height;

         var str = "";
         for (var i = 1; i <7; i++) {
             str = "wx_standby_" + (i < 10 ? ("0" + i) : i) + ".png";
             var frame = cc.spriteFrameCache.getSpriteFrame(str);
             this.walkFrames.push(frame);
         }

         for (var i = 1; i < 7; i++) {
             str = "wx_Attack_" + (i < 10 ? ("0" + i) : i) + ".png";
             var frame = cc.spriteFrameCache.getSpriteFrame(str);
             this.fightFrames.push(frame);
         }

         for (var i = 1; i < 7; i++) {
             str = "wx_dead_" + (i < 10 ? ("0" + i) : i) + ".png";
             var frame = cc.spriteFrameCache.getSpriteFrame(str);
             this.deadFrames.push(frame);
         }
         this.walkAnimation = new cc.Animation(this.walkFrames, 0.3);
         this.walkAnimate = cc.animate(this.walkAnimation);

         this.fightAnimation = new cc.Animation(this.fightFrames, 0.1);
         this.fightAnimate = cc.animate(this.fightAnimation);

         this.deadAnimation = new cc.Animation(this.deadFrames, 0.4);
         this.deadAnimate = cc.animate(this.deadAnimation);

         this.runAction(this.walkAnimate.repeatForever());
    },
    collideRect:function (x, y) {
        var w = this.initW, h = this.initH;
        return cc.rect(MW.ACTOR.X - w / 2, MW.ACTOR.Y - h / 4, w/2, h / 2+20);
    },
    fightRect:function(x, y){
        var w = this.initW, h = this.initH;
        return cc.rect(MW.ACTOR.X - w / 2, MW.ACTOR.Y - h / 4, w*1.1, h / 2+20);
    },
    fight:function(){
        this.x = this.fightPosition.x
        this.y = this.fightPosition.y
        this.runAction(this.fightAnimate.repeat(1));
        cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.sword_wav : res.sword_mp3, false);
                this.runAction(cc.sequence(
                    this.fightAnimate,
                    cc.callFunc(this.backposition, this)
                ));
    },
    dead:function(){
        this.stopAllActions();
        this.runAction(this.deadAnimate.repeat(1));
    },
    backposition:function(node){
        node.x = node.appearPosition.x;
        node.y = node.appearPosition.y;
    }
});


